package com.kangye.exam.controller;

import com.kangye.exam.bean.WrongTopic;
import com.kangye.exam.service.ItemSercice;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("errorItem")
public class ItemErroController {

    @Resource
    private ItemSercice itemSercice;

    @RequestMapping("/errorItem")
    public Object findItemAll(Integer page,Integer limit,Integer studentId) {
        Map<String,Object>map = new HashMap<>();
        page = (page-1)*limit;
        List<WrongTopic> itemAll = itemSercice.findItemAll(studentId,page,limit);
        if (itemAll != null) {
            map.put("code",0);
            map.put("count",itemSercice.getCount(studentId));
            map.put("data",itemAll);
            map.put("limit",limit);
        }else {
            map.put("code",-1);
        }
        return map;
    }

    @RequestMapping("/delitem")
    public Object deleteUser(Integer itemId,Integer studentId){
        Map<String,Object>map = new HashMap<>();
        if (itemId != null) {
            itemSercice.delItem(itemId,studentId);
            map.put("code",0);
        }else {
            map.put("code",-1);
        }
        return map;
    }

}
